home *** CD-ROM | disk | FTP | other *** search
- /*
- $VER: DirTree.dopus5 0.8 (23.10.98)
-
- Displays a simple directory tree in a lister and allows you to:
-
- a) Doubleclick on a directory to read it into the lister.
- b) Drop files on to a directory to copy/move them.
- c) Drag'n'Drop a directory into another lister for reading.
- d) Drag'n'Drop between DirTree listers to do some grafting.
-
- Drag'n'Drop to Copy, hold down shift key to Move.
-
- Call as: ARexx DOpus5:ARexx/DirTree.dopus5 [REGEN|CREATE] <Device>
-
- Flags Run Async
-
- where: REGEN = forces a new directory tree file to be created.
- CREATE = just creates the directory tree file then exits.
- Device = the device, eg. HD0:, SD0:, DF0:, etc.
-
- Examples: DirTree.dopus5 HD0:
- DirTree.dopus5 REGEN HD1:
- DirTree.dopus5 CREATE DH2:
-
- NOTE: For each device that you run this script on, a file called '.dirtree'
- will be created in the root directory. Reading the directory tree can
- take a while, but only needs to be done once, UNLESS you delete the
- '.dirtree' file or specify the REGEN option.
-
- Tip: ReOrg your HD, it'll make the listing of directories a lot faster.
-
- REQUIRES: rexxtricks.library in Libs: can be found on Aminet as
- util/rexx/RexxTricks_386.lha
-
- A working PIPE: device! (Required for grafting.)
-
- */
- graft = 1 /* Grafting is a function in BETA state, if you don't want or */
- /* don't trust it then set to 0. */
- stored = 0
- lf = '0a'x
-
- options results
- parse arg regen device
- if device = '' then device = regen
- create = upper(regen) = 'CREATE'
- regen = regen ~= device
-
- address 'DOPUS.1'
- if ~show('l','rexxsupport.library') then
- call addlib('rexxsupport.library',0,-30)
- if ~show('l','rexxtricks.library') then
- if ~addlib('rexxtricks.library',0,-30) then do
- dopus request '"Unable to load rexxtricks.library" OK'
- exit
- end
- if ~showlist('h','PIPE') & graft then do
- text = '"PIPE: device not mounted'||lf||'Disable Grafting or Mount PIPE:" Disable|Mount'
- if ~exists('DEVS:DOSDrivers/PIPE') then
- if ~exists('SYS:Storage/DOSDrivers/PIPE') then
- text = '"PIPE: device not found'||lf||'Grafting disabled!" OK'
- else stored = 1
- dopus request text
- if ~rc then
- if stored then
- address command 'Mount SYS:Storage/DOSDrivers/PIPE'
- else
- address command 'Mount PIPE:'
- end
- graft = showlist('h','PIPE') & graft
-
- device = strip(strip(device,,'"'))
- if pos(':',device) = 0 then do
- dopus request '"Specify DEVICE only, eg. ''HD0:''" OK'
- exit
- end
- device = left(device,pos(':',device))
- if ~exists(device) then do
- dopus request '"Device '''device''' does not exist!" OK'
- exit
- end
- oldcd = pragma('d',device)
- device = pragma('d',oldcd)
- tfile = device||'.dirtree'
- if regen then call delete(tfile)
-
- call whowantssome
-
- lister new invisible mode name
- handle = result
- lister set handle field off
- lister set handle toolbar
- lister set handle busy on
- lister set handle path ''
- lister set handle title 'DirTree of 'device
- lister set handle header 'Total of 'dirs.0' dirs.'
- lister refresh handle full
- lister set handle visible on
- call rackemup
- lister set handle busy off
-
- handlerport = 'DirTree'handle
- call openport(handlerport)
- lister set handle handler handlerport subdrop quotes nopopups
-
- do until event = 'inactive'
- if waitpkt(handlerport) then do
- packet = getpkt(handlerport)
- if packet ~= '00000000'x then do
- event = getarg(packet,0)
- namestr = getarg(packet,2)
- user = getarg(packet,3)
- args = getarg(packet,5)
- qualifier = getarg(packet,6)
- select
- when event = 'reread' then do
- call delete(tfile)
- call whowantssome
- call rackemup
- end
- when event = 'doubleclick' | event = 'path' then do
- if event ~= 'path' then do
- lister query handle value namestr
- namestr = result
- end
- lister set handle handler
- lister set handle toolbar toolbar
- lister set handle field on
- lister wait handle quick
- lister read handle namestr force
- leave
- end
- when event = 'drop' & index(qualifier,'subdrop') > 0 then do
- if index(qualifier,'shift') then
- cmd = 'Move'
- else
- cmd = 'Copy'
- if checkhandler(user) then do
- lister query handle value args
- path = result
- rescan = 0
- call getall
- do i = 1 to entries.count
- 'command original wait 'cmd' NAME='entries.i' TO='path
- end
- if rescan then do
- call delete(tfile)
- call whowantssome
- call rackemup
- end
- end
- else if graft then call graftit
- end
- when event = 'dropfrom' then do
- if checkhandler(user) then do
- parse var namestr line namestr
- lister query handle value line
- path = result
- lister read user path force
- end
- else if graft then call graftwait
- end
- otherwise
- end
- call reply(packet,0)
- if event ~= 'inactive' then do
- lister set handle header 'Total of 'dirs.0' dirs.'
- lister refresh handle full
- end
- end
- end
- end
-
- call closeport(handlerport)
- exit
-
- getall:
- i = 0
- do while namestr ~= ''
- i = i + 1
- parse var namestr '"' entries.i '"' namestr
- lister query user entry '"'entries.i'"' stem fileinfo.
- if fileinfo.TYPE > 0 then rescan = 1
- end
- entries.count = i
- return
-
- checkhandler: procedure
- parse arg user
- lister query user handler
- return (result = 'RESULT' | result = '')
-
- graftit:
- lister query user handler
- otoh = result
- if left(otoh,7) ~= 'DirTree' then return
- lister query handle value args
- newpath = result
- call getall
- lister query user value entries.1
- origpath = result
- if right(origpath,1) = ':' then return
- origdev = left(origpath,pos(':',origpath))
- ofile = origdev'.dirtree'
- call readfile(ofile,'odirs')
- oindex = lsearch('~('origpath'#?)','odirs',entries.1,'n','p')
- if oindex = -1 then oindex = odirs.0 + 1
- 'command original wait 'cmd' NAME="'origpath'" TO="'newpath'"'
- if ~rc then do
- ptail = lastpos('/',origpath)
- do i = entries.1 to oindex - 1
- odirs.i = newpath||substr(odirs.i,ptail)
- end
- call steminsert('dirs',2,oindex - entries.1,'')
- call stemcopy('odirs',entries.1,'dirs',2,oindex - entries.1)
- call qsort('dirs')
- call delete(tfile)
- call writefile(tfile,'dirs')
- call rackemup
- if cmd = 'Move' then do
- call stemremove('odirs',entries.1,oindex - entries.1)
- call delete(ofile)
- call qsort('odirs')
- call writefile(ofile,'odirs')
- address command 'echo >pipe:'otoh' 1'
- end
- else address command 'echo >pipe:'otoh' 0'
- end
- else do
- dopus request '"The Graft failed!" OK'
- address command 'echo >pipe:'otoh' 0'
- end
- return
-
- graftwait:
- lister query user handler
- otoh = result
- if left(otoh,7) ~= 'DirTree' then return
- call open('inpipe','PIPE:'handlerport,'r')
- wasit = readch('inpipe')
- call close('inpipe')
- if wasit then do
- call whowantssome
- call rackemup
- end
- return
-
- rackemup:
- lister clear handle
- lister refresh handle
- info.NAME = copies('0',nlength)
- info.TYPE = 4
- info.DISPLAY = device
- lister addstem handle info.
- lister set handle value info.NAME device
- info.TYPE = 1
- do j = 1 to dirs.0
- dirline = dirs.j
- path = dirline
- if pos(':',dirline) ~= 0 then parse var dirline dev ':' dirline
- if dirline ~= '' then do
- if pos('/',dirline) ~= 0 then do
- howmany = 0
- do while pos('/',dirline) ~= 0
- parse var dirline fore'/'dirline
- howmany = howmany + 1
- end
- dirline = copies(' ',3 * howmany)||dirline
- end
- dirline = ' '||dirline
- do i = 1 to length(dirline) by 3
- if substr(dirline,i + 3,3) ~= ' ' then do
- dirline = overlay('+--',dirline,i)
- leave
- end
- end
- info.NAME = right(j,nlength,'0')
- info.DISPLAY = dirline
- lister addstem handle info.
- lister refresh handle
- lister set handle value info.NAME path
- end
- end
- return
-
- whowantssome:
- if ~exists(tfile) then do
- call getdir(device,,'dirs','d','p','s')
- call qsort('dirs')
- call writefile(tfile,'dirs')
- 'command protect 'tfile' set H'
- if create then exit
- end
- else do
- if ~readfile(tfile,'dirs') then do
- dopus request '"ERROR: Unable to open '''tfile''' file." OK'
- exit
- end
- end
- nlength = length(dirs.0)
- return
-